/*
 * author nellson
 * date 2010-07-18
 * note calc time cost when call another module
 */

#ifndef _MODULE_CALL_H_
#define _MODULE_CALL_H_

#include "tsc.h"

namespace modulecall
{

#define call_start() 		CModuleCall::Instance()->Start();
#define call_end()		CModuleCall::Instance()->End();
#define call_timecost()	CModuleCall::Instance()->TimeCost()

class CModuleCall
{
	public:
		static CModuleCall * Instance()
		{
			if (!m_instance)
			{
				m_instance =  new CModuleCall;
				return m_instance;
			}

			return m_instance;
		};	

	public:
		void Start()
		{
			mtime(m_msec);
		};
		
		void End()
		{
			long long endtime;
			mtime(endtime);
			
			m_msec = endtime - m_msec;
		};
		
		long long TimeCost()
		{
			return m_msec;
		};

	private:
		CModuleCall(){tsc_init();};
		virtual ~CModuleCall(){};
		
	protected:
		long long m_msec;	

	protected:
		static CModuleCall * m_instance;
};

CModuleCall * CModuleCall::m_instance = 0;

};

#endif

